#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct node{
    ll left,right;
    ll num,id;
};
node cs[1000005],b[1000005];
ll h[1000005],h1[1000005];
vector<ll> car[1000005];
bool cmp(node x,node y){
    return x.num<y.num;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ll t,n,m,l,s,d,v,a,w,s1=0,s2=0,x;
    cin>>t;
    while(t--){
        cin>>n>>m>>l>>s;
        s1=s2=0;
        for(ll i=1;i<=n;i++){
            cin>>d>>v>>a;
            if(a==0){
                if(v>s){
                    cs[i].left=d,cs[i].right=l;
                }
                else cs[i].left=cs[i].right=-1;
            }
            else {
                w=ceil((3*3-v*v)*1.0/(2*a))+d;
                if(w<d||w>l) cs[i].left=d,cs[i].right=l;
                else {
                    if(d<=s) cs[i].left=w+1,cs[i].right=l;
                    else cs[i].left=d,cs[i].right=w-1;
                }
            }
        }
        ll ma=0,ans=0;
        for(ll i=1;i<=m;i++){
            cin>>x;
            for(ll j=1;j<=n;j++){
                if(x>=cs[j].left&&x<=cs[j].right){
                    if(!h[j]){
                        s1++;
                        h[j]=1;
                    }
                    car[j].push_back(x);
                    h1[x]++;
                    if(h1[x]==1) ans++;
                    ll len=car[j].size();
                    ma=max(ma,len);
                }
            }
        }
        for(ll i=1;i<=n;i++){
            b[i].num=car[i].size();
            b[i].id=i;
        }
        sort(b+1,b+n+1,cmp);
        memset(h,0,sizeof(h));
        ll f=0,f1,s3=0;
        s2=m-ans;
        for(ll i=1;i<=n;i++){
            f=f1=s3=0;
            for(ll j=0;j<car[b[i].id].size();j++){
                if(!h[car[b[i].id][j]]){
                    f++;
                    s3++;
                    h[car[b[i].id][j]]=1;
                    if(s3==2){
                        f1=1;
                        s2++;
                        s3--;
                    }
                }
            }
            if(f&&f1==0&&car[b[i].id].size()>1) {
                s2+=f;
            }
        }
        cout<<s1<<" "<<s2<<"\n";
        memset(cs,0,sizeof(cs));
        memset(b,0,sizeof(b));
        for(ll i=1;i<=n;i++) car[i].clear();
    }
    return 0;
}
